from flask import session
from flask_restful import Resource

from app.models import User, Collection, Poem, db


class Collect_addResource(Resource):
    def get(self):
        pass

    def post(self, p_id):
        if session['u_name']:
            name = session['u_name']
            user = User.query.filter(User.u_name == name)
            user = user.first()
            u_id = user.u_id
            p = Poem.query.get(p_id)
            c = Collection.query.get(u_id)
            p.collects.append(c)
            db.session.commit()
            return {'status': 200, 'msg': 'success'}
        else:
            return {'status': 400, 'msg': 'please login'}

    def put(self):
        pass

    def delete(self):
        pass